package androidlab.sprintingsquirrel.game;

import java.io.IOException;
import java.text.DecimalFormat;
import java.util.HashSet;

import org.andengine.engine.camera.hud.HUD;
import org.andengine.engine.camera.hud.controls.AnalogOnScreenControl;
import org.andengine.engine.camera.hud.controls.AnalogOnScreenControl.IAnalogOnScreenControlListener;
import org.andengine.engine.camera.hud.controls.BaseOnScreenControl;
import org.andengine.engine.handler.timer.ITimerCallback;
import org.andengine.engine.handler.timer.TimerHandler;
import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.LoopEntityModifier;
import org.andengine.entity.modifier.ScaleModifier;
import org.andengine.entity.scene.background.AutoParallaxBackground;
import org.andengine.entity.scene.background.ParallaxBackground.ParallaxEntity;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.entity.text.TextOptions;
import org.andengine.extension.physics.box2d.FixedStepPhysicsWorld;
import org.andengine.extension.physics.box2d.PhysicsConnector;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.input.touch.TouchEvent;
import org.andengine.util.HorizontalAlign;
import org.andengine.util.SAXUtils;
import org.andengine.util.debug.Debug;
import org.andengine.util.level.IEntityLoader;
import org.andengine.util.level.LevelLoader;
import org.andengine.util.level.constants.LevelConstants;
import org.xml.sax.Attributes;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.Manifold;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.opengl.GLES20;
import androidlab.sprintingsquirrel.BaseScene;
import androidlab.sprintingsquirrel.Constants;
import androidlab.sprintingsquirrel.ResourceManager;
import androidlab.sprintingsquirrel.SceneManager;
import androidlab.sprintingsquirrel.SceneManager.SceneType;
import androidlab.sprintingsquirrel.game.LevelCompleteWindow.HazelnutCount;

public class GameScene extends BaseScene {
	
	private PhysicsWorld physicsWorld;
	
	private int contactCounter = 0;
	private int hazelCounter = 0;
	protected int hazelsTotal;
	private boolean endpointSet;
	
	private HUD hud;
	
	private Player player;

	private Text hazelCntText;
	private LevelCompleteWindow levelCompleteWindow;
	private GameOverWindow gameOverWindow;
	private boolean gameOverDisplayed = false;
	private boolean gameCompletedDisplayed = false;

	private Text timerText;
	protected int timer = 0;
	
	private HashSet<Monster> monsters;

	@Override
	public void createScene() {
		monsters = new HashSet<Monster>();
		createBackground();
		createHUD();
		createPhysics();
		loadLevel();
		createCompletedWindow();
		createGameOverWindow();
	}

	@Override
	public void onBackKeyPressed() {
		new AlertDialog.Builder(resourceManager.activity)
		.setIcon(android.R.drawable.ic_dialog_alert)
		.setTitle("Spiel beenden")
		.setMessage("Soll das Spiel wirklich beendet werden?")
		.setPositiveButton("Ja", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				SceneManager.getInstance().loadMenuScene();
			}
		})
		.setNegativeButton("Nein", null)
		.show();
	}

	@Override
	public SceneType getSceneType() {
		return SceneType.GAME;
	}

	@Override
	public void disposeScene() {
		camera.setHUD(null);
	    camera.setCenter(640, 640*resourceManager.aspectRatio);
	    camera.setChaseEntity(null);
	}
	
	private void createBackground() {
		Sprite background = new Sprite(0, 0, resourceManager.gameBackgroundTR, vbom);
	    background.setScale(3);
		final AutoParallaxBackground autoParallaxBackground = new AutoParallaxBackground(0, 0, 0, 5);
        autoParallaxBackground.attachParallaxEntity(new ParallaxEntity(0.0f, background));
        setBackground(autoParallaxBackground);
	}
	
	private void createCompletedWindow() {
		levelCompleteWindow = new LevelCompleteWindow(vbom,GameScene.this);
	}
	
	private void createGameOverWindow() {
		gameOverWindow = new GameOverWindow(vbom,GameScene.this);
	}
	
	private void createHUD() {
	    hud = new HUD();
	    camera.setHUD(hud);
	    
	    hazelCntText = new Text(20, 0, resourceManager.font, "Hazels: 1000000", new TextOptions(HorizontalAlign.LEFT), vbom);
	    hazelCntText.setSkewCenter(0, 0);
	    hazelCntText.setText("Hazels: 0");
	    hud.attachChild(hazelCntText);
		
		timerText = new Text(1280-320, 0, resourceManager.font, "00:00", new TextOptions(HorizontalAlign.RIGHT), vbom);
		timerText.setSkew(0, 0);
		hud.attachChild(timerText);
		
		final DecimalFormat df = new DecimalFormat("00");
		this.registerUpdateHandler(new TimerHandler(1, true, new ITimerCallback() {
			
			@Override
			public void onTimePassed(TimerHandler pTimerHandler) {
				timer++;
				timerText.setText(df.format(timer/60) + ":" + df.format(timer%60));
			}
		}));
	    
	    Sprite button = new Sprite(1280-200, 1280*resourceManager.aspectRatio - resourceManager.knobTR.getHeight()-120, resourceManager.knobTR, vbom){
			@Override
			public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
				if(contactCounter > 0) {
					player.jump();
				}
				return false;
			}
		};

		hud.attachChild(button);
		hud.registerTouchArea(button);
		
		final float x1 = 80;
		final float y1 = 1280*resourceManager.aspectRatio - resourceManager.baseTR.getHeight()-80;
		final AnalogOnScreenControl velocityOnScreenControl = new AnalogOnScreenControl(
				x1, y1, this.camera, resourceManager.baseTR, resourceManager.knobTR, 0.1f,
				vbom,
				new IAnalogOnScreenControlListener() {
					@Override
					public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
						player.run(pValueX);
					}

					@Override
					public void onControlClick(
							final AnalogOnScreenControl pAnalogOnScreenControl) {
						/* Nothing. */
					}
				});
		velocityOnScreenControl.getControlBase().setBlendFunction(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
		velocityOnScreenControl.getControlBase().setAlpha(0.2f);

		this.setChildScene(velocityOnScreenControl);
	}
	
	private void createPhysics() {
	    physicsWorld = new FixedStepPhysicsWorld(60, new Vector2(0, 100), false);
	    physicsWorld.setContactListener(contactListener());
	    registerUpdateHandler(physicsWorld);
	}
	
	private void loadLevel() {
		hazelsTotal = 0;
	    final LevelLoader levelLoader = new LevelLoader();
	    
	    final FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(0, 0, 0);
	    
	    levelLoader.registerEntityLoader(LevelConstants.TAG_LEVEL, new IEntityLoader() {
	        public IEntity onLoadEntity(final String pEntityName, final Attributes pAttributes) {
	            final int width = SAXUtils.getIntAttributeOrThrow(pAttributes, LevelConstants.TAG_LEVEL_ATTRIBUTE_WIDTH);
	            final int height = SAXUtils.getIntAttributeOrThrow(pAttributes, LevelConstants.TAG_LEVEL_ATTRIBUTE_HEIGHT);
	            
	            camera.setBounds(0, 0, width, height);
	            camera.setBoundsEnabled(true);

	            return GameScene.this;
	        }
	    });
	    	    
	    levelLoader.registerEntityLoader(Constants.TAG_ENTITY, new IEntityLoader() {
	        public IEntity onLoadEntity(final String pEntityName, final Attributes pAttributes) {
	            final int x = SAXUtils.getIntAttributeOrThrow(pAttributes, Constants.TAG_ENTITY_ATTRIBUTE_X);
	            final int y = SAXUtils.getIntAttributeOrThrow(pAttributes, Constants.TAG_ENTITY_ATTRIBUTE_Y);
	            final String type = SAXUtils.getAttributeOrThrow(pAttributes, Constants.TAG_ENTITY_ATTRIBUTE_TYPE);
	            
	            final Sprite levelObject;
	            
	            
	            //Black Blocks
	            if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            } 
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_QUAD2X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuad2XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_QUAD3X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuad3XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_45NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangle45NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(-3.0f, 1.0f), new Vector2(3.0f, -3.0f), new Vector2(3.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_90NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangle90NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(1.0f, -3.0f), new Vector2(3.0f, -3.0f), new Vector2(-1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangle45TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -1.0f), new Vector2(-3.0f, -3.0f), new Vector2(3.0f, 1.0f), new Vector2(3.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -3.0f), new Vector2(-1.0f, -3.0f), new Vector2(3.0f, 3.0f), new Vector2(1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangleHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_HORI2X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangleHori2XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_RECTANGLE_VERTI2X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackQuadRectangleVerti2XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle135TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle180TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle45TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2X135TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly,  BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2X180TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2X45TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2X90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_VERTI_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2XVerti135TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_VERTI_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2XVerti180TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_VERTI_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2XVerti45TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BLACK_TRIANGLE2X_VERTI_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBlackTriangle2XVerti90TR, vbom);
	                Vector2[] poly = {new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            
	            
	          //Soil Blocks
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            } 
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_QUAD2X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Quad2XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_QUAD3X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Quad3XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_45NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangle45NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(-2.4f, 1.0f), new Vector2(3.0f, -3.0f), new Vector2(3.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_90NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangle90NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(1.0f, -3.0f), new Vector2(3.0f, -3.0f), new Vector2(-1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangle45TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -1.0f), new Vector2(-3.0f, -3.0f), new Vector2(3.0f, 1.0f), new Vector2(3.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -3.0f), new Vector2(-1.0f, -3.0f), new Vector2(3.0f, 3.0f), new Vector2(1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangleHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_HORI2X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangleHori2XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_RECTANGLE_VERTI2X)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1QuadRectangleVerti2XTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle135TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle180TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle45TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2X135TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly,  BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2X180TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2X45TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2X90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_VERTI_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2XVerti135TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_VERTI_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2XVerti180TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_VERTI_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2XVerti45TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENTEXTUR1_TRIANGLE2X_VERTI_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodentextur1Triangle2XVerti90TR, vbom);
	                Vector2[] poly = {new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            
	            
	          //Soil-Grass Blocks
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_L_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasLQuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_L_QUAD2x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasLQuad2xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_L_QUAD3x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasLQuad3xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_L_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasLRectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_L_RECTANGLE2x_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasLRectangle2xVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOQuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_QUAD2x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOQuad2xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_QUAD3x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOQuad3xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangle45TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -1.0f), new Vector2(-3.0f, -3.0f), new Vector2(3.0f, 1.0f), new Vector2(3.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE_45NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangle45NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(-3.0f, 1.0f), new Vector2(3.0f, -3.0f), new Vector2(3.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -3.0f), new Vector2(-1.0f, -3.0f), new Vector2(3.0f, 3.0f), new Vector2(1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangleHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE2x_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangle2xHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE2x_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangle2xVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle45TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle135TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle180TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2x45TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2x90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2x135TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2x180TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_VERTI_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2xVerti45TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_VERTI_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2xVerti90TR, vbom);
	                Vector2[] poly = {new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_VERTI_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2xVerti135TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_TRIANGLE2x_VERTI_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOTriangle2xVerti180TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLQuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_QUAD2x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLQuad2xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_QUAD3x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLQuad3xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangle45TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -1.0f), new Vector2(-3.0f, -3.0f), new Vector2(3.0f, 1.0f), new Vector2(3.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE_45NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangle45NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(-3.0f, 1.0f), new Vector2(3.0f, -3.0f), new Vector2(3.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE_90NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangle90NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(1.0f, -3.0f), new Vector2(3.0f, -3.0f), new Vector2(-1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_O_RECTANGLE_90NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORectangle90NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(1.0f, -3.0f), new Vector2(3.0f, -3.0f), new Vector2(-1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangleHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE2x_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangle2xHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_RECTANGLE2x_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLRectangle2xVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_TRIANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLTriangle45TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_TRIANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLTriangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_TRIANGLE2x_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLTriangle2x45TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_TRIANGLE2x_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLTriangle2x90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 2.0f), new Vector2(-3.0f, -2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_TRIANGLE2x_VERTI_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLTriangle2xVerti45TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OL_TRIANGLE2x_VERTI_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasOLTriangle2xVerti90TR, vbom);
	                Vector2[] poly = {new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORQuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_QUAD2x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORQuad2xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_QUAD3x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORQuad3xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE_45)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangle45TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -1.0f), new Vector2(-3.0f, -3.0f), new Vector2(3.0f, 1.0f), new Vector2(3.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE_45NEG)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangle45NegTR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, 3.0f), new Vector2(-3.0f, 1.0f), new Vector2(3.0f, -3.0f), new Vector2(3.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE_90)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangle90TR, vbom);
	                Vector2[] poly = {new Vector2(-3.0f, -3.0f), new Vector2(-1.0f, -3.0f), new Vector2(3.0f, 3.0f), new Vector2(1.0f, 3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangleHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE2x_HORI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangle2xHoriTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_RECTANGLE2x_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORRectangle2xVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_TRIANGLE_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORTriangle135TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, -1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_TRIANGLE_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORTriangle180TR, vbom);
	                Vector2[] poly = {new Vector2(1.0f, 1.0f), new Vector2(-1.0f, 1.0f), new Vector2(1.0f, -1.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_TRIANGLE2x_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORTriangle2x135TR, vbom);
	                Vector2[] poly = {new Vector2(-2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_TRIANGLE2x_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORTriangle2x180TR, vbom);
	                Vector2[] poly = {new Vector2(3.0f, 2.0f), new Vector2(-3.0f, 2.0f), new Vector2(3.0f, -2.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_TRIANGLE2x_VERTI_135)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORTriangle2xVerti135TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, -3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_OR_TRIANGLE2x_VERTI_180)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasORTriangle2xVerti180TR, vbom);
	                Vector2[] poly = {new Vector2(2.0f, 3.0f), new Vector2(-2.0f, 3.0f), new Vector2(2.0f, -3.0f)};
	                final Body body = PhysicsFactory.createPolygonBody(physicsWorld, levelObject, poly, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_R_QUAD)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasRQuadTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_R_QUAD2x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasRQuad2xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_R_QUAD3x)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasRQuad3xTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_R_RECTANGLE_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasRRectangleVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_BLOCK_BODENGRAS_R_RECTANGLE2x_VERTI)) {
	                levelObject = new Sprite(x, y, resourceManager.blockBodengrasRRectangle2xVertiTR, vbom);
	                final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	                body.setUserData("ground");
	                physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            }
	            
	            
	            //Items
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_HAZELNUT)) {
	            	hazelsTotal++;
	                levelObject = new Sprite(x, y, resourceManager.hazelnut_TR, vbom) {
	                	boolean collided = false;
	                    @Override
	                    protected void onManagedUpdate(float pSecondsElapsed) {
	                        super.onManagedUpdate(pSecondsElapsed);
	                        
	                        if (player.collidesWith(this) && !collided) {
	                        	addToHazelCounter(1);
	                        	this.setVisible(false);
	                        	collided = true;
	                        	ResourceManager.getInstance().eatSound.play();
	                        	if(!endpointSet && hazelCounter == hazelsTotal) {
	                        		displayGameCompletedText();
	                        	}
	                        }
	                    }
	                };
	                levelObject.registerEntityModifier(new LoopEntityModifier(new ScaleModifier(1, 1, 1.3f)));
	            }
	            //Logical entities
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_PLAYER)) {
	                player = new Player(x, y, vbom, camera, physicsWorld) {
	                    @Override
	                    public void onDie() {
	                    	if (!gameOverDisplayed && !gameCompletedDisplayed) {
	                            displayGameOverWindow();
	                        }
	                    }
	                };
	                levelObject = player;
	            }
	          //Logical entities
	            else if (type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_MONSTER)) {
	                levelObject = new Monster(x, y, vbom, camera, physicsWorld);
	                ((Monster) levelObject).animate(new long[] { 30, 30, 30 }, 0, 2,  true);
	                monsters.add((Monster) levelObject);
	            }
	            
	            else if(type.equals(Constants.TAG_ENTITY_ATTRIBUTE_TYPE_VALUE_END)) {
	            	levelObject = new Sprite(x, y, resourceManager.endTR, vbom);
	            	final Body body = PhysicsFactory.createBoxBody(physicsWorld, levelObject, BodyType.StaticBody, FIXTURE_DEF);
	            	body.setUserData("end");
	            	physicsWorld.registerPhysicsConnector(new PhysicsConnector(levelObject, body, true, false));
	            	endpointSet = true;
	            }
	                
	            else {
	                throw new IllegalArgumentException();
	            }
	            
	            levelObject.setCullingEnabled(true);

	            return levelObject;
	        }
	    });

	    try {
	    	levelLoader.loadLevelFromStream(activity.openFileInput(resourceManager.getLevel()));
		} catch (IOException e) {
			Debug.e(e);
		}
	}
	
	private void addToHazelCounter(int i){
		hazelCounter += i;
		hazelCntText.setText("Hazels: " + hazelCounter);
	}

	private void displayGameOverWindow() {
	    camera.setChaseEntity(null);
	    gameOverWindow.display(GameScene.this, camera);
	    gameOverDisplayed = true;
	    camera.setHUD(null);
		this.clearChildScene();
		ResourceManager.getInstance().music.pause();
		ResourceManager.getInstance().gameOverSound.play();
		
		engine.registerUpdateHandler(new TimerHandler(5.8f, new ITimerCallback() {
				@Override
				public void onTimePassed(TimerHandler pTimerHandler) {
					engine.unregisterUpdateHandler(pTimerHandler);
					ResourceManager.getInstance().music.resume();
				}
		}));
	}
		
	private void displayGameCompletedText() {
		gameCompletedDisplayed = true;
		double hazelCounter = this.hazelCounter;
		double hazelsTotal = this.hazelsTotal;
		if(hazelCounter<=(hazelsTotal*(1.0/3.0))) {
			levelCompleteWindow.display(HazelnutCount.ONE, GameScene.this, camera, timer, this.hazelCounter, this.hazelsTotal);
		}
		else if ((hazelCounter>(hazelsTotal*(1.0/3.0))) && (hazelCounter <= (hazelsTotal*(2.0/3.0)))) {
			levelCompleteWindow.display(HazelnutCount.TWO, GameScene.this, camera, timer, this.hazelCounter, this.hazelsTotal);
		}
		else {
			levelCompleteWindow.display(HazelnutCount.THREE, GameScene.this, camera, timer, this.hazelCounter, this.hazelsTotal);
		}
		camera.setChaseEntity(null);
		camera.setHUD(null);
		this.clearChildScene();
		player.run(0);
		ResourceManager.getInstance().music.pause();
		ResourceManager.getInstance().levelCompleteSound.play();
		
		engine.registerUpdateHandler(new TimerHandler(5f, new ITimerCallback() {
				@Override
				public void onTimePassed(TimerHandler pTimerHandler) {
					engine.unregisterUpdateHandler(pTimerHandler);
					ResourceManager.getInstance().music.resume();
				}
		}));
	}
	
	private ContactListener contactListener() {
	    ContactListener contactListener = new ContactListener() {
	        public void beginContact(Contact contact) {
	            final Fixture x1 = contact.getFixtureA();
	            final Fixture x2 = contact.getFixtureB();

	            if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feet")) {
	                contactCounter++;
	    			player.setContactCounter(contactCounter);
	    			if(player.getCurrentTileIndex() == 3) {
	    				player.setCurrentTileIndex(1);
	    			}
	    			else if(player.getCurrentTileIndex() == 4) {
	    				player.setCurrentTileIndex(6);
	    			}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feet") && x2.getBody().getUserData().equals("ground")) {
	            	contactCounter++;
	    			player.setContactCounter(contactCounter);
	    			if(player.getCurrentTileIndex() == 3) {
	    				player.setCurrentTileIndex(1);
	    			}
	    			else if(player.getCurrentTileIndex() == 4) {
	    				player.setCurrentTileIndex(6);
	    			}
	            }
	            else if (x1.getBody().getUserData().equals("end") && x2.getUserData() != null && x2.getUserData().equals("feet")) {
	            	displayGameCompletedText();
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feet") && x2.getBody().getUserData().equals("end")) {
	            	displayGameCompletedText();
	            }
	            else if (x1.getBody().getUserData().equals("player") && x2.getBody().getUserData().equals("monster")) {
	            	if(!gameOverDisplayed && !gameCompletedDisplayed) {
	            		displayGameOverWindow();
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("monster") && x2.getBody().getUserData().equals("player")) {
	            	if(!gameOverDisplayed && !gameCompletedDisplayed) {
	            		displayGameOverWindow();
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feetLeft")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.addLeftContacts();
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetLeft") && x2.getBody().getUserData().equals("ground")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.addLeftContacts();
		            	}
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feetRight")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.addRightContacts();
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetRight") && x2.getBody().getUserData().equals("ground")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.addRightContacts();
		            	}
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feetLeftHead")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.setDirection(true);
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetLeftHead") && x2.getBody().getUserData().equals("ground")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.setDirection(true);
		            	}
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feetRightHead")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.setDirection(false);
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetRightHead") && x2.getBody().getUserData().equals("ground")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.setDirection(false);
		            	}
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("end") && x2.getUserData() != null && x2.getUserData().equals("feetLeftHead")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.setDirection(true);
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetLeftHead") && x2.getBody().getUserData().equals("end")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.setDirection(true);
		            	}
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("end") && x2.getUserData() != null && x2.getUserData().equals("feetRightHead")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.setDirection(false);
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetRightHead") && x2.getBody().getUserData().equals("end")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.setDirection(false);
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetRightHead") && x2.getUserData() != null && x2.getUserData().equals("feetLeftHead")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.setDirection(false);
		            	}
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.setDirection(true);
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetLeftHead") && x2.getUserData() != null && x2.getUserData().equals("feetRightHead")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.setDirection(true);
		            	}
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.setDirection(false);
		            	}
	            	}
	            }
	        }

	        public void endContact(Contact contact) {
	            final Fixture x1 = contact.getFixtureA();
	            final Fixture x2 = contact.getFixtureB();

	            if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feet")) {
	                contactCounter--;
	    			player.setContactCounter(contactCounter);
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feet") && x2.getBody().getUserData().equals("ground")) {
	                contactCounter--;
	    			player.setContactCounter(contactCounter);
	            }
	            else if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feetLeft")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.removeLeftContacts();
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetLeft") && x2.getBody().getUserData().equals("ground")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.removeLeftContacts();
		            	}
	            	}
	            }
	            else if (x1.getBody().getUserData().equals("ground") && x2.getUserData() != null && x2.getUserData().equals("feetRight")) {
	            	for(Monster monster : monsters) {
		            	if(x2.getBody().equals(monster.getBody())) {
		            		monster.removeRightContacts();
		            	}
	            	}
	            }
	            else if (x1.getUserData() != null && x1.getUserData().equals("feetRight") && x2.getBody().getUserData().equals("ground")) {
	            	for(Monster monster : monsters) {
		            	if(x1.getBody().equals(monster.getBody())) {
		            		monster.removeRightContacts();
		            	}
	            	}
	            }
	        }

	        public void preSolve(Contact contact, Manifold oldManifold) {
	        }

	        public void postSolve(Contact contact, ContactImpulse impulse) {
	        }
	    };
	    return contactListener;
	}
}
